package com.ganbo.thread.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by gan on 2020/5/20 22:18.
 */
public class LockDemo extends Thread {

    private Lock lock = new ReentrantLock();

    @Override
    public void run() {
        lock.lock();
        for (int i = 0; i < 5; i++) {
            System.out.println(Thread.currentThread().getName() + "========>" + (i + 1));
        }
        lock.unlock();
    }


    public static void main(String[] args) {
        LockDemo lockDemo = new LockDemo();

        Thread t1 = new Thread(lockDemo);
        Thread t2 = new Thread(lockDemo);
        Thread t3 = new Thread(lockDemo);
        Thread t4 = new Thread(lockDemo);
        Thread t5 = new Thread(lockDemo);

        t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();
    }
}
